package com.sisgesbyte.dao.ventas;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.sisgesbyte.dao.utilDao.CreaFiltroSqlString;
import com.sisgesbyte.data.entity.ventas.PeriodoEntity;
import com.sisgesbyte.data.util.AbstractFacade;

@Stateless
public class MantenimientoPeriodoDaoImpl extends AbstractFacade<PeriodoEntity> implements MantenimientoPeriodoDao {

	@Inject
	private CreaFiltroSqlString creaFiltroSqlString;
	
	@PersistenceContext(unitName = "SigesSiscompPU")
	private EntityManager em;

	@Override
	protected EntityManager getEntityManager() {
		return em;
	}
	
	public MantenimientoPeriodoDaoImpl(){
		super(PeriodoEntity.class);
	}

	@Override
	public List<PeriodoEntity> listaPeriodos() {
		
		StringBuilder jpql = new StringBuilder();
		jpql.append("SELECT id, descripcion, defecto, active FROM ventas.periodo ");
		jpql.append("where active = :active ");
		Query query = em.createNativeQuery(jpql.toString(), PeriodoEntity.class);
			query.setParameter("active", true);
		List<PeriodoEntity> ls = query.getResultList();

		return ls;
		
	}
	
}
